package com.ruoyi.web.controller.community.cpc;

import java.util.List;

import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.CpcBbsComment;
import com.ruoyi.community.service.ICpcBbsCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 党员论坛评论Controller
 * 
 * @author ruoyi
 * @date 2021-12-23
 */
@RestController
@RequestMapping("/community/cpc/post/comment")
public class CpcBbsCommentController extends BaseController
{
    @Autowired
    private ICpcBbsCommentService cpcBbsCommentService;

    /**
     * 查询党员论坛评论列表
     */
//    @PreAuthorize("@ss.hasPermi('community:comment:list')")
    @GetMapping("/list")
//    public TableDataInfo list(CpcBbsComment cpcBbsComment)
//    {
//        startPage();
//        List<CpcBbsComment> list = cpcBbsCommentService.selectCpcBbsCommentList(cpcBbsComment);
//        return getDataTable(list);
//    }
    public AjaxResult list(CpcBbsComment cpcBbsComment)
    {
        List<CpcBbsComment> list = cpcBbsCommentService.selectCpcBbsCommentList(cpcBbsComment);
        return AjaxResult.success(list);
    }

    /**
     * 获取党员论坛评论详细信息
     */
//    @PreAuthorize("@ss.hasPermi('community:comment:query')")
//    @GetMapping(value = "/{commentId}")
//    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
//    {
//        return AjaxResult.success(cpcBbsCommentService.selectCpcBbsCommentById(commentId));
//    }
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        CpcBbsComment cpcBbsComment = new CpcBbsComment();
        cpcBbsComment.setPostId(commentId);
//        return AjaxResult.success(cpcBbsCommentService.selectCpcBbsCommentList(cpcBbsComment));
        return AjaxResult.success(cpcBbsCommentService.getSortedCommentPackList(cpcBbsComment));
    }

//    @GetMapping(value = "/{postId}")
//    public AjaxResult getInfo(@PathVariable("postId") Long postId)
//    {
//        return AjaxResult.success(cpcBbsCommentService.selectCpcBbsCommentByPostId(postId));
//    }

    /**
     * 新增党员论坛评论
     */
//    @PreAuthorize("@ss.hasPermi('community:comment:add')")
    @Log(title = "党员论坛评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CpcBbsComment cpcBbsComment)
    {
        return toAjax(cpcBbsCommentService.insertCpcBbsComment(cpcBbsComment));
    }

    /**
     * 修改党员论坛评论
     */
//    @PreAuthorize("@ss.hasPermi('community:comment:edit')")
    @Log(title = "党员论坛评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CpcBbsComment cpcBbsComment)
    {
        return toAjax(cpcBbsCommentService.updateCpcBbsComment(cpcBbsComment));
    }

    /**
     * 删除党员论坛评论
     */
//    @PreAuthorize("@ss.hasPermi('community:comment:remove')")
    @Log(title = "党员论坛评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(cpcBbsCommentService.deleteCpcBbsCommentByIds(commentIds));
    }

    /**
     * 导出党员论坛评论列表
     */
//    @PreAuthorize("@ss.hasPermi('community:comment:export')")
    @Log(title = "党员论坛评论", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CpcBbsComment cpcBbsComment)
    {
        List<CpcBbsComment> list = cpcBbsCommentService.selectCpcBbsCommentList(cpcBbsComment);
        ExcelUtil<CpcBbsComment> util = new ExcelUtil<CpcBbsComment>(CpcBbsComment.class);
        return util.exportExcel(list, "党员论坛评论数据");
    }
}
